package com.arwtec.controller;

import com.arwtec.model.ResultModel;
import com.arwtec.model.User;
import com.arwtec.service.IUserService;
import com.arwtec.util.ResultResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService userService;

    @GetMapping
    public ResultModel list() {
        return ResultResponseUtil.success(userService.list());
    }

    @GetMapping("/{id}")
    public ResultModel findById(@PathVariable("id") Long id) {
        return ResultResponseUtil.success(userService.getById(id));
    }

    @PostMapping
    public ResultModel saveUser(@RequestBody User user){
        return ResultResponseUtil.success(userService.save(user));
    }

    @PutMapping
    public ResultModel updateUser(@RequestBody User user) {
        return ResultResponseUtil.success(userService.updateById(user));
    }

    @DeleteMapping("/{id}")
    public ResultModel deleteUserById(@PathVariable("id") Long id) {
        return ResultResponseUtil.success(userService.removeById(id));
    }
}
